package rmmk.ksr.experiments;

import java.util.Arrays;
import java.util.List;

import org.junit.Test;

import rmmk.algorithms.features.FeatureManager;
import rmmk.algorithms.features.FrequentNumbersGlobal;
import rmmk.algorithms.features.fatures.NumberExtractor;
import rmmk.algorithms.features.global.GlobalClassesWordCount;
import rmmk.algorithms.features.global.PairsOfWordsGlobal;
import rmmk.algorithms.preprocessing.OperationManager;
import rmmk.algorithms.preprocessing.WordExtractor;
import rmmk.algorithms.preprocessing.abstraction.IWordFilter;
import rmmk.algorithms.preprocessing.filters.ToLowercaseNoInterpunctionFilter;
import rmmk.datasources.parsing.ClassTypes;
import rmmk.datasources.parsing.DocumentReader;
import rmmk.framework.Analize;
import rmmk.framework.datasources.Document;
import rmmk.framework.datasources.DocumentSetSelector;

public class BestConfigTest15 {
	
	@Test
	public void ex1test() {
		//for (int i = 1; i < 38; i += 4) {
			Long start = System.nanoTime();

			OperationManager om = new OperationManager();

			DocumentReader dr = new DocumentReader();

			List<Document> allDocuments = dr.readDefautDocuments();

			IWordFilter[] iwe = new IWordFilter[] { new ToLowercaseNoInterpunctionFilter() };
			WordExtractor.extractWords(allDocuments, Arrays.asList(iwe));

			DocumentSetSelector dss = new DocumentSetSelector(allDocuments);
			dss.addDesiredCategory(ClassTypes.PLACES);
			dss.setLimit(1);
			dss.addCategoryName("west-germany");
			dss.addCategoryName("usa");
			dss.addCategoryName("france");
			dss.addCategoryName("uk");
			dss.addCategoryName("canada");
			dss.addCategoryName("japan");

			List<Document> trainDocuments = dss.getTrainSet();

			PairsOfWordsGlobal pwg = new PairsOfWordsGlobal();
			pwg.calculate(trainDocuments);
			FrequentNumbersGlobal ng = new FrequentNumbersGlobal();
			ng.calculate(trainDocuments);
			GlobalClassesWordCount gcwc = new GlobalClassesWordCount();
			gcwc.process(trainDocuments);

			FeatureManager fm = new FeatureManager();
			// fm.addFeature(new PairsOfWordsExtractor(43), new
			// NumberExtractor(5),
			// new NumbersWordsExtractor());
			System.out.println("dodajemy cechy");
			fm.addFeature(
					//new NumbersWordsExtractor(), 
					//new PairsOfWordsExtractor(10), 
					new NumberExtractor(5)//, 
					//new GlobalClassesWordCountExtractor(10)
					);

			
			om.setFeatureManager(fm);
			System.out.println("trenowanie");
			om.teach(trainDocuments);

			System.out.println("ustawiamy k");
			om.setK(5);

			List<Document> testDocuments = dss.getTestSet();

			System.out.println("predict");
			testDocuments = om.predict(testDocuments);

			Analize.analize(testDocuments);
			Long finished = System.nanoTime();

			System.out.println("Czas " + (finished - start) / 1000000000
					+ " sekund");
		//}
	}
}
